package com.pybox.repository;

import com.pybox.dto.Result;
import com.pybox.dto.TUsersDto;
import com.pybox.dto.UserObjectsDto;
import com.pybox.entity.TUsers;
import com.pybox.oauth.conf.UserDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
* 描述：TUsers Repository
* @author wuyingkai
* @date 2018-09-15
*/

@Repository
public interface TUsersRepository extends JpaRepository<TUsers, Integer>, JpaSpecificationExecutor<TUsers>   {
    @Query(value = "select * from t_users  where username = ?1 and deleted = 0",nativeQuery =true )
    TUsers getLoginUser(String username);

    @Modifying
    @Query(value = " update t_users set password = ?1 where id = ?2",nativeQuery = true)
    Integer resetPassword(String  newPassword,Integer id);

    @Modifying
    @Query(value = "update t_users set is_admin =?1 where id=?2",nativeQuery = true)
   Integer upDateAdminByUserId(Integer isAdmin,Integer userId);

    @Query(value = "select count(1) from t_users where password=?1 and id =?2 and deleted =0",nativeQuery = true)
    Integer checkPassword(String password, Integer userId);

    @Query(value = "select count(1)  from t_users where username = ?1 and customer_id =?2 and deleted =0 " ,nativeQuery = true)
    Integer checkUserNameUnique(String username,Integer customerId);

    @Query(value = "select count(1) from t_users where password =?1 and customer_id=?2 and delete =0",nativeQuery = true)
    Integer checkUserPasswordUnique( String password,Integer customerId);

}